/**
 * 
 */
package com.pub.proxy;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URLConnection;

import com.pub.util.HttpUtils;

/**
 * @author iling
 *
 */
public class Test 
{

	/**
	 * 
	 */
	public Test() 
	{
		
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) 
	{
		

//		HttpURLConnection connSetURL;
//		String content = null;
//		try {
//			System.out.println("*******************start****************************************");
//			
//			connSetURL = HttpUtils.getHttpConnURL("http://77.76.25.8:8085", 15000);
//			
//			System.out.println("http code ============== " + connSetURL.getResponseCode());
//			if(connSetURL.getResponseCode() == 200){
//				content = HttpUtils.getContent(connSetURL);
//				System.out.println("get content.============== " + content);
//			}
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
		
	
//		URLConnection connURL;
//		content = null;
//		try {
//			System.out.println("***********************************************************");
//			connURL = HttpUtils.getConnURL("http://77.76.25.8:8085");
//			
//			
//			content = HttpUtils.getContent(connURL);
//			System.out.println(" connURL get content.============== " + content);
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}

		
		
		URLConnection connSetURL;
		ProxyManager proxyManager = ProxyManager.getInstance(Test.class.getName(), "crawler", "/home/workspace/crawler/configs/");
		Proxy proxy;
		
		int counter		= 0;
		String content 	= null;
		try {
			
//			while(content == null){
				counter++;
//				Thread.sleep(10000);
				System.out.println(counter + " get proxy...");
				System.out.println("11proxy element size : " + proxyManager.getProxyElementSize());
				
				proxy = proxyManager.getProxy();
				
				System.out.println("22proxy element size : " + proxyManager.getProxyElementSize());
			
//				connSetURL = HttpUtils.getConnURL("http://www.baidu.com", proxy);
//				
//				
//				System.out.println("get content...");
//	//			HttpUtils.sendPost(connSetURL, "");
//				
//				
//				
//				
//				content = HttpUtils.getContent(connSetURL);
//				System.out.println("out === " + content);
//				
//				if(content == null){
//					System.out.println("----------********************************---------");
//					
//					System.out.println("invalid host : " + proxy.getHost());
//					System.out.println("invalid port : " + proxy.getPort());
//					
//					proxy.setInvalid();
//				}else{
//					System.out.println("----------===========================--------");
//					
//					System.out.println("valid host : " + proxy.getHost());
//					System.out.println("valid port : " + proxy.getPort());
//					
//					proxy.setValid();
//					
//				}
				
				proxyManager.freeProxy(proxy);
				
				System.out.println("proxy element size : " + proxyManager.getProxyElementSize());
//			}
			//;;;
			
		} catch (Exception e) {
			System.out.print("-----------------------------------------------------");
			e.printStackTrace();
		}
		
		proxyManager.close();

		System.out.println("--------------eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee---------------------");
		
	}

}
